Hello, I'm relatively new to DXL; running an old version of DOORS (7.1).
I'm defining skip lists that contain strings holding regular expression text. As each skip list is passed into a function for processing, I'd like to avoid issuing regexp calls on strings that have already been converted by creating a global skip list of processed regular expressions with the key containing the regular expression and the data value containing the regexp result. How can this be done if the skip list will contain the address of the variable containing the regexp result? If the variable is local to the function isn't the address of the variable invalid once the function exits? If the variable is global then it gets reused with each function call causing previous regexp results, referenced in the skip list, to get overwritten. Any help would be appreciated.
Sidar - Fri Oct 07 08:59:37 EDT 2011 |
|
Re: regexp - avoid repeating call on same regular expression llandale - Fri Oct 07 13:39:49 EDT 2011
This has been working for me:
Skip gl_RegExp_skpMake = createString() // KEY: 'string' converted search; DATA: 'Regexp' equivalent
inside function
if (!find(gl_RegExp_skpMake, SearchString, reSearch))
{ reSearch = regexp2(SearchString)
put(gl_RegExp_skpMake, SearchString, reSearch)
}
if (reSearch TargetString) then match found
|
|
Re: regexp - avoid repeating call on same regular expression Sidar - Fri Oct 07 17:14:13 EDT 2011 llandale - Fri Oct 07 13:39:49 EDT 2011
This has been working for me:
Skip gl_RegExp_skpMake = createString() // KEY: 'string' converted search; DATA: 'Regexp' equivalent
inside function
if (!find(gl_RegExp_skpMake, SearchString, reSearch))
{ reSearch = regexp2(SearchString)
put(gl_RegExp_skpMake, SearchString, reSearch)
}
if (reSearch TargetString) then match found
Thanks Louie for your response and your contribution to other posts. I've been keeping links to some of them for future reference.
Your example code is exactly what I was hoping would work. However, it does suggest that DOORS either stores the content of the reSearch variable in the skip list or it creates a separate instance of the reSearch variable each time the function is invoked in order to retain previous data for the skip list. Any insight would be appreciated.
Sidar
|
|
Re: regexp - avoid repeating call on same regular expression Mathias Mamsch - Sat Oct 08 07:48:53 EDT 2011 Sidar - Fri Oct 07 17:14:13 EDT 2011
Thanks Louie for your response and your contribution to other posts. I've been keeping links to some of them for future reference.
Your example code is exactly what I was hoping would work. However, it does suggest that DOORS either stores the content of the reSearch variable in the skip list or it creates a separate instance of the reSearch variable each time the function is invoked in order to retain previous data for the skip list. Any insight would be appreciated.
Sidar
Louies code should be correct. Only if the skip list does NOT contain the regexp already (find returns false), then a new regexp is created and put into the cache. If the regexp was already created and is in the cache, then the find will return true and put the already created regexp in the 'reSearch' variable. It is a very general caching pattern, which also works for nested skips.
Regards, Mathias
Mathias Mamsch, IT-QBase GmbH, Consultant for Requirement Engineering and D00RS
|
|